package cn.logo.junit.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.logo.dao.AddressDao;
import cn.logo.entities.Address;
import cn.logo.service.AddressService;

public class LogoTest01 {
	private ClassPathXmlApplicationContext ctx;
	@Before
	public void init(){
		ctx = new ClassPathXmlApplicationContext("spring-mvc.xml");
	}
	@After
	public void destory(){
		ctx.close();
		System.out.println("关闭ioc容器");
	}
	@Test
	public void test01(){
		SqlSessionFactory ssf = (SqlSessionFactory)ctx.getBean("ssf");
		SqlSession session = ssf.openSession();
		System.out.println(session);
	}
	@Test
	public void test02(){
		AddressDao ad = ctx.getBean(AddressDao.class);
		List<Address> list = ad.getAddressByUserId(2);
		for(Address a:list){
			System.out.println(a);
		}
	}
	@Test
	public void test03(){
		AddressService as = ctx.getBean(AddressService.class);
		List<Address> list = as.getAddress(2);
		for(Address a:list){
			System.out.println(a);
		}
		
	}
}
